/************************************************************
 * Copyright (C), 2022-2030, dina. Co., Ltd.
 * FileName:        can_plugin.h
 * Author:          Dan Yin
 * Date:            2023-05-12
 * Description:     the class of can plugin
 * Version:         1.0.0.0
 **********************************************************/

#ifndef CAN_PLUGIN_H
#define CAN_PLUGIN_H

#include "i_can.h"
#include "defines/def_frame_protocol.h"

#include <QThread>
class CanPlugin : public ICan
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID ICan_iid FILE "can.json")
    Q_INTERFACES(ICan)

public:
    // default constructor
    explicit CanPlugin(QObject *parent = nullptr);

    // open a CAN
    int openCAN();

    // close a CAN
    void closeCAN();

    // send an frame data to CAN bus
    int sendFrameData(ST_CAN_FRAME stCanFrame, bool bQueued);

signals:

private slots:
    int slotSendFrameData(ST_CAN_FRAME stCanFrame, bool bQueued);

    int slotSendFrameData(unsigned int nFrameId, const QByteArray &baFrameData, bool bQueued);

    // Close thread after finish
    void slotDeleteThread();

    // received data from CAN
    void slotDataReceived(unsigned int unCanId, QByteArray baPacket);

private:
    QObject *m_pParent;
    QThread  m_thrDeviceWorker;
    QThread  m_thrManageWorker;
};

#endif // CAN_PLUGIN_H
